home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / brik2src.zip / ADDBFCRC.ASM next >
Assembly Source File  |  1989-08-04  |  2KB  |  78 lines

  1. ; ::[[ @(#) addbfcrc.asm 1.1 89/07/08 10:48:28 ]]::
  2. ; assembly implementation of addbfcrc() for Turbo C 2.0 -- small memory model
  3.  
  4. ; The following code was obtained from compiling addbfcrc.c using
  5. ; Turbo C 2.0, then hand-optimized.  In the interest of making
  6. ; faster CRC-32 calculations available to all, I hereby release
  7. ; the contents of this file to the public domain.  This code is for
  8. ; the small memory model only.  It will probably need to be revised
  9. ; for use with other C compilers.
  10. ;                                    -- Rahul Dhesi 1989/07/08
  11.  
  12. _DATA   segment word public 'DATA'
  13. _DATA   ends
  14.  
  15.         extrn   _crccode:word
  16.         extrn   _crctab:word
  17.         public  _addbfcrc
  18.  
  19. _TEXT   segment byte public 'CODE'
  20.  
  21. DGROUP  group   _DATA
  22.         assume  cs:_TEXT,ds:DGROUP,ss:DGROUP
  23.  
  24. ;void addbfcrc (buf, size) char *buf, int size
  25.  
  26. _addbfcrc       proc    near
  27.         push    bp
  28.         mov     bp,sp
  29.         sub     sp,2
  30.         push    si
  31.         push    di
  32.         mov     cx,word ptr [bp+6]      ;cx = size
  33.         mov     si,word ptr [bp+4]      ;si = buf
  34.  
  35.         xor     di,di                   ;i = 0
  36.  
  37.         jcxz    done                    ;if size = 0, nothing to do
  38. @loop:
  39.  
  40. ;      crccode = crctab[(int) ((crccode) ^ (buf[i])) & 0xff] ^
  41. ;         (((crccode) >> 8) & 0x00FFFFFFL);
  42.  
  43. ;       (dx,ax) <- ((crccode) >> 8) & 0x00FFFFFFL
  44.         mov     dx,word ptr DGROUP:_crccode+2
  45.         mov     ax,word ptr DGROUP:_crccode
  46.         mov     al,ah
  47.         mov     ah,dl
  48.         mov     dl,dh
  49.         xor     dh,dh
  50.  
  51.         mov     bx,di                   ;bx <= i
  52.  
  53.         mov     bl,byte ptr [bx+si]     ;bl <- buf[i]
  54.  
  55.         xor     bl,byte ptr DGROUP:_crccode ;bl <- (bl ^ crccode) & 0xff
  56.         xor     bh,bh                   ;bx <- bl
  57.         shl     bx,1
  58.         shl     bx,1                    ;bx <- 4 * bx (for subscript)
  59.  
  60.         xor     ax,word ptr DGROUP:_crctab[bx]
  61.         xor     dx,word ptr DGROUP:_crctab[bx+2]
  62.         mov     word ptr DGROUP:_crccode+2,dx
  63.         mov     word ptr DGROUP:_crccode,ax
  64.  
  65.         inc     di              ; i++
  66.         loop    @loop
  67. done:
  68.  
  69.         pop     di
  70.         pop     si
  71.         mov     sp,bp
  72.         pop     bp
  73.         ret     
  74. _addbfcrc       endp
  75.  
  76. _TEXT   ends
  77.         end
  78.